import java.util.List;

import models.Event;
import models.Project;
import models.Task;
import models.TaskUserUser;
import models.User;

import org.junit.Test;

import controllers.Tasks;

import play.test.UnitTest;
import junit.framework.TestCase;


public class C3Story9And10UnitTesting extends UnitTest {

	
	
	
@Test
public void TestAllgetUserTaskRelation(){
User mous = new User("moustafa","mohamed","magdy","mous","1234","mous221@gmail.com","012","sda","cairo","egypt","");
User tarek = new User("tarek","","aboel3azm","sheihkT","21","","","","","","");	
mous.save();
tarek.save();
Task t= new Task();	
t.description="task1";
Task r= new Task();	
r.description="task2";
Task y= new Task();	
y.description="task3";
t.save();
r.save();
y.save();

TaskUserUser TUU1= new TaskUserUser(mous,t);
TUU1.save();
TaskUserUser TUU2= new TaskUserUser(mous,tarek,r);
TUU2.save();
TaskUserUser TUU3 = new TaskUserUser(tarek,y);
TUU3.save();



List<TaskUserUser> tTUU= t.getUserTaskRelation();
List<TaskUserUser> tmrTUU= r.getUserTaskRelation(tarek,mous);
List<TaskUserUser> uTUU= tarek.getUserTaskRelation();
List<TaskUserUser> tmTUU= mous.getUserTaskRelation();

assertTrue("t",tTUU.get(0).equals(TUU1));
assertTrue("tmr",tmrTUU.get(0).equals(TUU2));
assertTrue("u",uTUU.get(0).equals(TUU2)&&uTUU.get(1).equals(TUU3));
assertTrue("tm",tmTUU.get(0).equals(TUU1));


	
	
}


@Test
public void TestgetFreeTasks(){
	
	Event e = new Event();
	
	


	User mous = new User("moustafa","mohamed","magdy","mous","1234","mous221@gmail.com","012","sda","cairo","egypt","");
	User tarek = new User("tarek","","aboel3azm","sheihkT","21","","","","","","");	
	mous.save();
	tarek.save();
	Task t= new Task();	
	t.description="task1";
	Task r= new Task();	
	r.description="task2";
	Task y= new Task();	
	y.description="task3";
	e.tasks.add(t);
	e.tasks.add(r);
	e.tasks.add(y);
	
	t.events.add(e);
	r.events.add(e);
	y.events.add(e);
	t.save();
	r.save();
	y.save();

	TaskUserUser TUU1= new TaskUserUser(mous,t);
	TUU1.save();
	TaskUserUser TUU2= new TaskUserUser(mous,tarek,r);
	TUU2.save();
	e.save();
	Project p = new Project("se","dasd",true);
	p.events.add(e);
	p.save();
	
	
List<Task> freeTasks = p.getFreeTask();	
	
	//assertTrue("1",freeTasks.get(0).equals(r));
	//assertTrue("2",freeTasks.get(1).equals(y));
	
	assertTrue("3",freeTasks.get(1).equals(r));
	assertTrue("4",freeTasks.get(0).equals(y));
	
	
	
	
}




}
